yjx.directive('touchReload', ['$timeout', function touchReload($timeout) {
    return {
        replace: false,
        restrict: "AEC",
        scope: {
            func: "=reloadFun",//需触发的加载函数
            touch: "=touchObj" //touch监听对象
        },
        link: function ($scope, elem, attr) {
            //监听手势当滚动条在位置0时且end_yy>0开始记录下移
            var loadingTips = elem.find('.reload-tips').find('i');
            var reloading = 0;//初始加载状态 0:未加载(可加载) 1:正在加载中(不可重新加载)
            var wc = $scope.$watch(attr.touchReload, function (newVal) {
                var tc = $scope.touch;
                if (tc && tc.allow2pd && tc.scrollTop == 0) {//存在touch事件且允许下拉且到顶
                    if (tc._y > 0 && tc._yy > 0 && tc._yy <= 40) {//40px以内赋值到margin-top
                        elem.css('margin-top', tc._yy + 'px');
                        if (tc._yy > 30) {
                            //loadingTips.next().html('释放刷新');
                        }
                        if (tc.end && tc.end_yy > 30 && reloading == 0) {//离开触屏时 30~40px加载数据
                            //loadingTips.next().html('');
                            loadingTips.addClass('icon-2x');
                            loadingTips.addClass('icon-spin');
                            loadingTips.css('animation', 'spin 1s infinite linear');
                            reloading++;
                            $scope.func();
                        }
                    } else if (tc.end && tc._y > 0 && tc.end_yy >= 40) {//离开触屏时 超过40px固定为40
                        elem.css('margin-top', '40px');
                    } else if (tc.end) {//离开触屏时
                        if (reloading > 0) {//正在加载中
                            //elem.addClass('pull-down-trans');
                            $timeout(function () {//动态效果
                                elem.css('transition', "-webkit-transform 300ms ease-out");
                                elem.css('webkitTransform', "translate(0px,-40px) scale(1) translateZ(0px)");
                            })
                            $timeout(function () {//清空动态效果
                                //elem.removeClass('pull-down-trans');
                                elem.css('margin-top', '0px');
                                elem.css('transition', '')
                                elem.css('webkitTransform', '')
                                loadingTips.removeClass('icon-2x');
                                loadingTips.removeClass('icon-spin');
                                loadingTips.css('animation', 'spin 0s');
                                //loadingTips.next().html('');
                            }, 500);
                            reloading = 0;//初始加载状态
                        } else {
                            elem.css('margin-top', '0px');
                        }
                    } else {
                        reloading = 0;//初始加载状态
                    }
                }
            })
        }
    }

}])